package com.unsanctioned.radioagregator.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

public class AppConfig {
	public static final String DOGTAG = AppConfig.class.getSimpleName();
	public static final String APP_CONFIG = "";
	public static AppConfig instance;
	private SharedPreferences sharedPreferences;
	/**
	 * Default constructor.
	 * @param context
	 */
	public AppConfig(Context context){
		this.sharedPreferences = context.getSharedPreferences(APP_CONFIG, Context.MODE_PRIVATE);
	}
	public static AppConfig getInstance(Context context) {
		if (instance == null) {
			return new AppConfig(context);
		} else return instance;
	}
	public SharedPreferences getAppConfig() {
		return this.sharedPreferences;
	}
	/**
	 * Store a string as a value with certain name in using SharedPreferences.
	 * @param confName - name of a value.
	 * @param confValue - value itself.
	 */
	public void storeString(String confName, String confValue) {
		this.sharedPreferences.edit().putString(confName, confValue).commit();
	}
	/**
	 * Store a boolean as a value with certain name in using SharedPreferences.
	 * @param confName - name of a value.
	 * @param confValue - value itself.
	 */
	public void storeBoolean(String confName, boolean confValue) {
		this.sharedPreferences.edit().putBoolean(confName, confValue).commit();
	}
	/**
	 * Retrieve a string value with provided name using SharedPreferences.
	 * @param confName
	 * @return a desired value or <b>null</b> if value is not found.
	 */
	public String getString(String confName) {
		return this.sharedPreferences.getString(confName, null);
	}
	/**
	 * Retrieve a boolean value with provided name using SharedPreferences.
	 * @param confName
	 * @return a desired value or <b>null</b> if value is not found.
	 */
	public boolean getBoolean(String confName) {
		return this.sharedPreferences.getBoolean(confName, false);
	}
	/**
	 * Delete value with provided name.
	 * @param confName
	 */
	public void deleteConfig(String confName) {
		this.sharedPreferences.edit().remove(confName).commit();
	}
	/**
	 * Delete all values with all names.
	 */
	public void clearConfig() {
		// This deletes all configuration value ever stored before.
		this.sharedPreferences.edit().clear().commit();
	}
}